package com.zwj.learning.timetable.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zwj.common.entity.Student;
import com.zwj.common.service.StudentService;
import com.zwj.common.service.UserService;
import com.zwj.learning.timetable.common.TokenThreadLocal;
import com.zwj.learning.timetable.entity.Grade;
import com.zwj.learning.timetable.entity.GradeLocalSemester;
import com.zwj.learning.timetable.service.GradeLocalSemesterService;
import com.zwj.learning.timetable.mapper.GradeLocalSemesterMapper;
import com.zwj.learning.timetable.service.GradeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author 23088
* @description 针对表【grade_local_semester(年级当前学期)】的数据库操作Service实现
* @createDate 2022-12-02 00:17:25
*/
@Service
public class GradeLocalSemesterServiceImpl extends ServiceImpl<GradeLocalSemesterMapper, GradeLocalSemester>
    implements GradeLocalSemesterService{

    @DubboReference
    private UserService userService;

    @DubboReference
    private StudentService studentService;

    @Resource
    private GradeService gradeService;

    @Override
    public Integer getGradeLocalSemester() {

        String currentToken = TokenThreadLocal.getCurrentToken();
        Long loginUserId = userService.getLoginUserId(currentToken);
        Student student = studentService.getStudentById(loginUserId);

        LambdaQueryWrapper<Grade> gradeWrapper = new LambdaQueryWrapper<>();
        gradeWrapper.eq(Grade::getGrade, student.getGrade());
        Grade grade = gradeService.getOne(gradeWrapper);

        GradeLocalSemester one = this.getOne(new LambdaQueryWrapper<GradeLocalSemester>()
                .eq(GradeLocalSemester::getGradeId, grade.getId()));

        return one.getSemesterId();
    }
}




